
// Dark GDK - The Game Creators - www.thegamecreators.com

// the wizard has created a very simple 3D project that uses Dark GDK
// it can be used as a starting point in making your own 3D games

// whenever using Dark GDK you must ensure you include the header file
#include "DarkGDK.h"
#include "Movement.h"
#include "SC_Collision.h"
float d;

// the main entry point for the application is this function
void DarkGDK ( void )
{
	// in this application we are going to create some 3D objects
	// and position them on screen

	// when starting a Dark GDK program it is useful to set global
	// application properties, we begin by turning the sync rate on,
	// this means we control when the screen is updated, we also set
	// the maximum rate to 60 which means the maximum frame rate will
	// be set at 60 frames per second
	dbSyncOn   ( );
	dbSyncRate ( 60 );

	// set our random seed to a value from the timer, this will help
	// to ensure each time we run our program the random values appear
	// more random
	dbRandomize ( dbTimer ( ) );

	dbLoadObject ( "feet.x", 1 );
	dbPositionObject (1,0, 0 , 0);
	dbRotateObject (1,-90,0,0);
	dbSetObjectLight (1,1);
	dbLoadObject ( "tutlvl.x", 2);
	dbPositionObject (2,0,-5,0);
	dbRotateObject (2,90,0,0);
	SC_Start();
	SC_SetupObject(1,1,0);
	SC_SetupObject(2 , 0 , 0); 
	SC_SetObjectCollisionOn(2);
	SC_DrawObjectBounds(2);
	// move our camera back so we can view the objects
	dbPositionCamera (0,5,0);
	dbRotateCamera (0 ,0, 0);


	// camera variables
	float fCameraAngleX = 0;
	float fCameraAngleY = 0;
	// object variables
	float startpositionx = 0;
	float startpositiony = 0;
	float startpositionz = 0;
	float g_fSpeed = 0.1f;
	float g_fTurn = 0.03f;
	float OldCamAngleY;
	float OldCamAngleX;
	float CameraAngleY;
	float CameraAngleX;
	int breckcollision;
	int direction;
	int  collision;
	// now we come to our main loop, we call LoopGDK so some internal
	// work can be carried out by the GDK
	while ( LoopGDK ( ) )
	{


		
		// display some text on screen
		dbText ( 0, 0, "Use the wasd keys to move the character forward, backward, left and right" );
		dbText (0, 14, "Use the mouse to change the camera angale");
		breckcollision = SC_GroupCollision(1,0);
		if (d=0); {
			dbControlCameraUsingArrowKeys ( 0, g_fSpeed, g_fTurn );

	OldCamAngleY = CameraAngleY;
	OldCamAngleX = CameraAngleX;

	CameraAngleY = dbWrapValue ( CameraAngleY + dbMouseMoveX ( ) * 0.4f );
	CameraAngleX = dbWrapValue ( CameraAngleX + dbMouseMoveY ( ) * 0.4f );

	dbYRotateCamera ( dbCurveAngle ( CameraAngleY, OldCamAngleY, 24 ) );
	dbXRotateCamera ( dbCurveAngle ( CameraAngleX, OldCamAngleX, 24 ) );

	char* szKey = dbInKey ( );

	if ( strcmp ( szKey, "+" ) == 0 )
	{
		if ( g_fSpeed < 1000 )
			g_fSpeed = g_fSpeed + 0.01f;
	}

	if ( strcmp ( szKey, "-" ) == 0 )
	{
		if ( g_fSpeed > 0.02f )
			g_fSpeed = g_fSpeed - 0.01f;
	}
	direction = Movement();

	
		// here we make a call to update the contents of the screen
		dbSync ( );
	}
	

	}


	return;
}